<template>
    <div class="listDiv">
        <div class="searchDiv">
            <DateRange v-model:start="obj.req.starttime" v-model:end="obj.req.endtime" sph="匹配" eph="申请时间" />
            <el-input clearable placeholder="匹配企业名称" v-model="obj.req.key" class="search_key" />
            <span class="btn search" @click="init">搜索</span>
            <span class="btn refresh" @click="obj.req.currentpage=1;init()"></span>
            <!-- <span class="btn download" @click="export_"></span>
            <div class="searchRight">
                <span class="btn add" @click="add">添加</span>
            </div> -->
        </div>
        <div class="table_box"><div class="table_" id="tb">
            <ul class="head">
                <li class="liflex">企业名称</li>
                <li class="li1">联系人</li>
                <li class="limobile">联系电话</li>
                <li class="li2">融资金额</li>
                <li class="li3">所属行业</li>
                <li class="mw200 wcen">申请时间</li>
                <li class="mw100 wcen">操作</li>
            </ul>
            <div class="body">
                <ul v-for="x in obj.ary" :key="x">
                    <li class="liflex">{{x.companyname}}</li>
                    <li class="li1">{{x.man}}</li>
                    <li class="limobile">{{x.mobile}}</li>
                    <li class="li2">{{x.price}}</li>
                    <li class="li3">{{(!x.industry||!+x.industry)?'暂无':x.industry}}</li>
                    <li class="mw200 wcen">{{x.intime}}</li>
                    <li class="liaction wcen">
                        <el-button class="read_btn" type="primary" @click="edit(x)">查看</el-button>
                    </li>
                </ul>
            </div>
        </div>
        </div><Pager :value="obj.req" :init="init" />

        <el-dialog v-model="obj.drawer.design" :title="obj.drawer.designTitle" width="1000px" :close-on-click-modal="false" :destroy-on-close="true">
            <router-view @close="obj.drawer.design = false" @init="init" />
        </el-dialog>
    </div>
</template>

<script setup>
    import { reactive, getCurrentInstance, ref, toRefs, provide, computed } from 'vue'
    import { ElMessageBox } from 'element-plus'
    import DateRange from '@/components/date_range.vue'
    import Pager from '@/components/pager.vue'
    let { proxy } = getCurrentInstance()

    let obj = reactive({
        drawer: {
            design: false,
            designTitle: "",
        },
        ary: [],
        req: {
            currentpage: 1,
            pagesize: 10,
            count: 0,
            key: "",
            endtime: "",
            starttime: "",
        }
    });
    let init = () => {
        proxy.$ajax({
            url: '/docking/list',
            data: obj.req,
            bfLoading: true
        }).then(d => {
            // console.log(d)
            if(d.success){
                obj.ary = d.msg.list
                obj.req.count = d.msg.count
            }
        }).catch(() => { })
    }

    let detail = ref({})
    provide("obj", detail); //不能加.value
    let edit = x => {
        // console.log(x)
        proxy.$ajax({
            url: '/docking/get',
            data: { docking_id: x.docking_id },
            bfLoading: true
        }).then(d => {
            console.log(d)
            if(d.success && d.msg.state){
                obj.drawer.design = true
                obj.drawer.designTitle = "查看详情"
                detail.value = d.msg.msg.msg
                return
            }
            if(d.msg.msg==='无查看权限，请联系运营管理员'){
                ElMessageBox.confirm('无查看权限，确认要申请吗？', '提示', {
                    confirmButtonText: '确定',
                    cancelButtonText: '取消',
                    distinguishCancelAndClose: true,
                }).then(() => {
                    proxy.$ajax({
                        url: '/docking/apply',
                        data: {},
                        bfLoading: true
                    }).then(d1 => {
                        // console.log(d1)
                        if(d1.success){
                            proxy.elMessageMixin("申请成功", 'success')
                        }else{
                            proxy.elMessageMixin(d1.err, 'error')
                        }
                    }).catch(() => { })
                }).catch(() => {})
            }
        }).catch(() => { })
    }
</script>

<style scoped>
    ::-webkit-scrollbar { width:10px; background-color: #FFFFFF; }
    .search_select { margin-left: 10px; width:100px!important; }
    .search_key { width:160px!important; }
    #tb ul li.li2 { width: 100px; }
    #tb ul li.li3 { width: 145px; }
    #tb ul li.li1 { width: 95px; }
</style>